package zut.cs.liziflower.controller;


import org.springframework.web.bind.annotation.*;
import zut.cs.liziflower.entity.Orderitems;
import zut.cs.liziflower.entity.Result;
import zut.cs.liziflower.service.impl.OrderitemsServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xuwenke
 * @since 2022-05-26
 */
@RestController
@RequestMapping("/api/orderitems")
public class OrderitemsController {

    @Resource
    private OrderitemsServiceImpl orderitemsService;

    @PostMapping("/add-order-items")
    public Result<?> addOrderItems(@RequestBody Orderitems orderitems) {
        int i = orderitemsService.addItem(orderitems.getOrderid(), orderitems.getUserid(),
                orderitems.getFlowerid(), orderitems.getNum());
        if (i == 1) {
            return Result.success("添加成功");
        }
        return Result.error("405", "添加失败", null);
    }

    @GetMapping("/get-all-items")
    public Result<?> getAllItems(@RequestParam("orderid") Integer orderid,
                                 @RequestParam("userid") Integer userid) {

        List<Orderitems> list = orderitemsService.getAllItems(orderid, userid);
        return Result.success(list);
    }

}
